"""Optional 类型配置

包含 Optional 类型的 C++ 映射和操作方法配置
"""

# Optional 类型配置
CONFIG = {
    # Optional 构造函数和全局函数
    "Optional": {
        "signatures": [
            "Optional() -> Optional[T]",
            "Optional(value: T) -> Optional[T]"
        ],
        "templates": [
            "std::optional<T>()",
            "std::optional<T>({value})"
        ],
        "includes": ["<optional>"],
        "priority": 1,
    },
    "Optional[T]": {
        "cpp_type": "std::optional<T>",
        "includes": ["<optional>"],
        "default_value": "std::optional<T>()",
        
        # 包装类型元信息（用于类型收窄系统）
        "wrapper_info": {
            "is_wrapper": True,
            "inner_type": "T",  # 内部类型是模板参数 T
            
            # 解包策略（按优先级排序）
            "unwrap_strategies": [
                {
                    "name": "method_call",
                    "pattern": "{self}.value()",
                    "condition": "always",  # 总是可用
                    "precedence": 2,  # . 运算符的优先级
                },
                {
                    "name": "dereference",
                    "pattern": "*{self}",
                    "condition": "always",
                    "precedence": 3,  # * 运算符的优先级
                }
            ],
            
            # 真值检查方法（用于 if 语句）
            "truthiness_check": "{self}.has_value()",
        },
        
        "methods": {
            "has_value": {
                "signatures": ["has_value(self) -> bool"],
                "templates": ["{self}.has_value()"],
                "includes": [],
                "priority": 1,
            },
            "value": {
                "signatures": ["value(self) -> T"],
                "templates": ["{self}.value()"],
                "includes": [],
                "priority": 1,
            },
            "value_or": {
                "signatures": ["value_or(self, default_value: T) -> T"],
                "templates": ["{self}.value_or({default_value})"],
                "includes": [],
                "priority": 1,
            },
            "reset": {
                "signatures": ["reset(self) -> None"],
                "templates": ["{self}.reset()"],
                "includes": [],
                "priority": 1,
                "mutating": True,
            },
            "__eq__": {
                "signatures": [
                    "__eq__(self, other: Optional[T]) -> bool",
                    "__eq__(self, other: T) -> bool",
                    "__eq__(self, other: None) -> bool"
                ],
                "templates": [
                    "{self} == {other}",
                    "{self}.has_value() && {self}.value() == {other}",
                    "!{self}.has_value()"
                ],
                "includes": [],
                "priority": 1,
            },
            "__ne__": {
                "signatures": [
                    "__ne__(self, other: Optional[T]) -> bool",
                    "__ne__(self, other: T) -> bool",
                    "__ne__(self, other: None) -> bool"
                ],
                "templates": [
                    "{self} != {other}",
                    "!{self}.has_value() || {self}.value() != {other}",
                    "{self}.has_value()"
                ],
                "includes": [],
                "priority": [1, 1, 2],  # None 类型签名优先级更高
            },
            "__bool__": {
                "signatures": ["__bool__(self) -> bool"],
                "templates": ["{self}.has_value()"],
                "includes": [],
                "priority": 1,
            },
        },
    }
}